package com.mmg.cosplay.config;

import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import dev.langchain4j.data.segment.TextSegment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Qdrant向量数据库配置
 * 
 * @author fly
 * @since 2025-9-24
 */
@Configuration
public class QdrantConfig {

    @Value("${qdrant.host:localhost}")
    private String qdrantHost;

    @Value("${qdrant.port:6334}")
    private Integer qdrantPort;

    @Value("${qdrant.use-tls:false}")
    private Boolean useTls;

    @Value("${qdrant.api-key:}")
    private String apiKey;

    /**
     * 创建Qdrant嵌入存储Bean
     * 注意：这里不指定collection名称，因为我们需要为每个角色创建独立的collection
     */
    @Bean
    public QdrantEmbeddingStore.Builder qdrantEmbeddingStoreBuilder() {
        QdrantEmbeddingStore.Builder builder = QdrantEmbeddingStore.builder()
                .host(qdrantHost)
                .port(qdrantPort)
                .useTls(useTls);
        
        if (apiKey != null && !apiKey.trim().isEmpty()) {
            builder.apiKey(apiKey);
        }
        
        return builder;
    }
}